package co.fitstart.admin.web.controller.course;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.demo2do.core.BusinessException;
import com.demo2do.core.support.Result;
import com.demo2do.core.utils.CollectionUtils;
import com.demo2do.core.utils.DateFormatUtils;
import com.demo2do.core.utils.DateUtils;
import com.demo2do.core.utils.JsonUtils;
import com.demo2do.core.web.utils.WebUtils;
import co.fitstart.admin.entity.course.ExperienceStat;
import co.fitstart.admin.entity.report.HourlySchedule;
import co.fitstart.admin.entity.report.WeeklySchedule;
import co.fitstart.admin.entity.security.Login;
import co.fitstart.admin.handler.ScheduleReportHandler;
import co.fitstart.admin.handler.TencentHandler;
import co.fitstart.admin.service.CoachService;
import co.fitstart.admin.service.CourseRoundService;
import co.fitstart.admin.service.CourseScheduleService;
import co.fitstart.admin.service.OrderService;
import co.fitstart.admin.service.PrincipalService;
import co.fitstart.admin.service.ProductService;
import co.fitstart.admin.service.RestCalendarService;
import co.fitstart.admin.service.ScheduleReportService;
import co.fitstart.admin.service.SiteService;
import co.fitstart.admin.web.interceptor.MenuSetting;
import co.fitstart.admin.web.resolver.Secure;
import co.fitstart.admin.web.view.ExcelTemplateView;
import co.fitstart.entity.coach.CoachRestCalendar;
import co.fitstart.entity.coach.CoachRestType;
import co.fitstart.entity.course.schedule.CourseSchedule;
import co.fitstart.entity.order.Order;
import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.product.Product;
import co.fitstart.entity.site.Site;

/**
 * 
 * @author mohanlan
 *
 */
@Controller
@RequestMapping("/schedules")
@MenuSetting("menu-course")
public class ScheduleController {
	
	@Autowired
	private TencentHandler tencentHandler;
    
    @Autowired
    private PrincipalService principalService;
    
    @Autowired
    private CourseScheduleService courseScheduleService;
    
    @Autowired
    private RestCalendarService restCalendarService;
    
    @Autowired
    private ScheduleReportService scheduleReportService;
    
    @Autowired
    private ProductService productService;
    
    @Autowired
    private CourseRoundService courseRoundService;
    
    @Autowired
    private OrderService orderService;
    
    @Autowired
    private ScheduleReportHandler scheduleReportHandler;
    
    @Autowired
    private SiteService siteService;
    
    @Autowired
    private CoachService coachService;
    
    private static final Logger logger = LoggerFactory.getLogger(ScheduleController.class);
    
    /**
     * Display course schedule & coach rest schedule
     * 
     * @param login
     * @param siteId
     * @param coachview
     * @param beginDate
     * @param weekOffset
     * @param coachId
     * @param week
     * @param request
     * @return
     */
    @MenuSetting("submenu-schedule")
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ModelAndView index(@Secure Login login,
                              @RequestParam(value = "site", required = false) Long siteId,
                              @RequestParam(value = "coachview", required = false, defaultValue = "true") String coachview,
                              @RequestParam(value = "beginDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginDate,
                              @RequestParam(value = "weekOffset", required = false) Integer weekOffset,
                              @RequestParam(value = "coachId", required = false) Long coachId,
                              @RequestParam(value = "week", required = false, defaultValue = "1") Integer week,
                              HttpServletRequest request) {
        
        ModelAndView modelAndView = new ModelAndView();
        if(coachview.equalsIgnoreCase("true")) {
            modelAndView.setViewName("course/schedule/schedule-coach-index");
        } else {
            modelAndView.setViewName("course/schedule/schedule-date-index");
        }
        Date today = new Date();
        modelAndView.addObject("today", today);
        
        Site site = null;
        if (!login.hasSite() && siteId != null) {
            site = siteService.load(siteId);
        }else if (login.hasSite()){
            site = login.getSite();
        }
        
        modelAndView.addObject("site", site);
        
        // set default weekOffset as 8
        if(weekOffset == null) {
            weekOffset = 4;
        }
        
        // add coach
        Principal coach = null;
        if(coachId != null) {
            coach = principalService.load(Principal.class, coachId);
        }
        
        // add coachview to switch how to display
        modelAndView.addObject("coachview", coachview);
        
        // set beginDate , endDate & list dates
        if(beginDate == null) {
            beginDate = today;
        }
        beginDate = DateUtils.addWeeks(DateUtils.getFirstWeekDay(beginDate), week-1);
        Date endDate = DateUtils.addDays(beginDate, 6);
        
        List<Date> dates = DateUtils.getIntervalDays(beginDate, endDate);
        String desc = DateFormatUtils.format(beginDate) + " 至 " + DateFormatUtils.format(endDate);
        
        modelAndView.addObject("desc", desc)
                    .addObject("dates", dates)
                    .addObject("weekOffset", weekOffset)
                    .addObject("week", week);
        
        List<CourseSchedule> result = new ArrayList<>();
        List<CoachRestCalendar> restSchedules = new ArrayList<>();
        
        if(site == null && (login.isAreaManager() || login.isAreaServer())) {
            Principal principal = principalService.load(Principal.class, login.getId());
            
            List<Site> sites = siteService.listSite(principal);
            
            if(!sites.isEmpty()) {
                result = courseScheduleService.listCourseSchedule(sites, coach, beginDate, endDate);
                
                restSchedules = restCalendarService.listRestCalendar(sites, coach, beginDate, endDate);
            }
        } else {
            result = courseScheduleService.listCourseSchedule(site, coach, beginDate, endDate);
            
            restSchedules = restCalendarService.listRestCalendar(site, coach, beginDate, endDate);
        }
        
        // list course schedules & map data
        
//        Map<String, List<CourseSchedule>> courseSchedulesMaps = new HashMap<String, List<CourseSchedule>>();
//        
//        List<CourseSchedule> courseSchedules = new ArrayList<CourseSchedule>();
//        courseSchedules.addAll(result);
//        for(CourseSchedule courseSchedule : result) {
//            courseSchedules.add(courseSchedule.addHalfHour());
//        }
//        courseSchedulesMaps  = CollectionUtils.constructMapValuesFromList(courseSchedules, "coach.id");
//        Map<String, Map<String, List<CourseSchedule>>> courseSchedulesResult = new HashMap<String, Map<String, List<CourseSchedule>>>(courseSchedulesMaps.size());
//        
//        for(String key : courseSchedulesMaps.keySet()) {
//          courseSchedulesResult.put(key, CollectionUtils.constructMapValuesFromList(courseSchedulesMaps.get(key), "dayhour"));
//        }
        modelAndView.addObject("courseSchedules", CollectionUtils.constructMapValuesFromList(result, "beginData"));
        
        // list rest schedules & map data
        
//        Map<String, List<CoachRestCalendar>> restScheduleMaps  = CollectionUtils.constructMapValuesFromList(restSchedules, "coach.id");
//        Map<String, Map<String, List<CoachRestCalendar>>> restSchedulesResult = new HashMap<String, Map<String, List<CoachRestCalendar>>>(restScheduleMaps.size());
//        
//        for(String key : restScheduleMaps.keySet()) {
//          restSchedulesResult.put(key, CollectionUtils.constructMapValuesFromList(restScheduleMaps.get(key), "hour"));
//        }
        modelAndView.addObject("restSchedules", CollectionUtils.constructMapValuesFromList(restSchedules, "beginData"));
        
        modelAndView.addObject("queryString", WebUtils.extractQueryString(request, "week"));
        
        return modelAndView;
    }
    
    /**
     * View schedule search page
     * 
     * @return
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public String search() {
        return "course/schedule/schedule-search";
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @return
     */
    @RequestMapping(value="/calendar-edit", method = RequestMethod.GET)
    public ModelAndView edit(@RequestParam("coach") Long coachId, 
                             @RequestParam("date")String date,
                             @RequestParam("site") Long siteId) {
        ModelAndView modelAndView = new ModelAndView("course/schedule/schedule-edit");
        
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String todayString = format.format(new Date());
        Date today = DateUtils.parseDate(todayString, "yyyy-MM-dd");
        modelAndView.addObject("today", today);
        
        Date day = DateUtils.parseDate(date, "yyyy-MM-dd");
        modelAndView.addObject("day", day);
        List<String> remainDays = co.fitstart.entity.utils.DateUtils.getMonthRemainDays();
       
        modelAndView.addObject("remainDays",remainDays);        
        modelAndView.addObject("coachId", coachId);
        modelAndView.addObject("date", date);
        modelAndView.addObject("siteId", siteId);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param type
     * @param coachId
     * @param date
     * @param businessHour
     * @param dutyHour
     * @param experienceHour
     * @param conferenceHour
     * @param trainingHour
     * @return
     */
    @RequestMapping(value = "/calendar-edit", method = RequestMethod.PATCH)
    public @ResponseBody String onEdit(@RequestParam("type") String type,
                                       @RequestParam("coach") Long coachId,
                                       @RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd")Date date,
                                       @RequestParam(value = "businessDays",required = false) List<String> businessDays,                                       
                                       @RequestParam(value = "businessHour", required = false) String businessHour,
                                       @RequestParam(value = "dutyHour", required = false) String dutyHour,
                                       @RequestParam(value = "trainingHour", required = false) String trainingHour,
                                       @RequestParam(value = "conferenceHour", required = false) String conferenceHour) {
        Result result = new Result();
        
        try {
            Principal coach = principalService.load(Principal.class, coachId);
            CoachRestType coachRestType = CoachRestType.aliasOf(type);
            
            if (coachRestType.isBusiness()) {
                restCalendarService.editRestCalendar(coach, coachRestType, date, businessHour,businessDays);
            } else if (coachRestType.isDuty()) {
                restCalendarService.editRestCalendar(coach, coachRestType, date, dutyHour,businessDays);
            } else if (coachRestType.isConference()) {
                restCalendarService.editRestCalendar(coach, coachRestType, date, conferenceHour,businessDays);
            } else if (coachRestType.isTraining()) {
                restCalendarService.editRestCalendar(coach, coachRestType, date, trainingHour,businessDays);
            }
            
            result.success().message("更改课时成功！");
            
        } catch (BusinessException e) {
            
            result.fail().message(e.getMessage());
            
        } catch (Exception e) {
            
            logger.error("onEdit error - ", e);
            result.fail().message("更改课时失败！");
        }
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @param siteId
     * @return
     */
    @RequestMapping(value="/add-experience", method = RequestMethod.GET)
    public ModelAndView addExperience(@Secure Login login,
                                      @RequestParam("coach") Long coachId,
                                      @RequestParam("date")String date) {
        ModelAndView modelAndView = new ModelAndView("course/schedule/schedule-add-experience");
        
        Date today = DateUtils.parseDate(DateFormatUtils.format(new Date(), "yyyy-MM-dd"), "yyyy-MM-dd");
        modelAndView.addObject("today", today);
        
        Date day = DateUtils.parseDate(date, "yyyy-MM-dd");
        modelAndView.addObject("day", day);
        
        Principal coach = principalService.load(Principal.class, coachId);
        
        if(login.hasSite()) {
            modelAndView.addObject("siteId", login.getSite().getId());
        } else {
            List<Site> sites = coachService.listCoachSite(coach, day);
            
            if(!sites.isEmpty()) {
                if(login.isAreaServer() || login.isAreaManager()) {
                    Principal principal = principalService.load(Principal.class, login.getId());
                    
                    List<Site> avaiableSites = siteService.listSite(principal);
                    
                    if(!avaiableSites.isEmpty()) {
                        List<Site> resultSites = new ArrayList<>();
                        
                        for(Site site : sites) {
                            if(avaiableSites.contains(site)) {
                                resultSites.add(site);
                            }
                        }
                        
                        modelAndView.addObject("sites", resultSites);
                        
                        if(!resultSites.isEmpty()) {
                            modelAndView.addObject("siteId", resultSites.get(0).getId());
                        }
                    }
                } else {
                    modelAndView.addObject("sites", sites);
                    
                    modelAndView.addObject("siteId", sites.get(0).getId());
                }
            }
        }
        
        modelAndView.addObject("coachId", coachId);
        modelAndView.addObject("date", date);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param coachId
     * @param siteId
     * @param date
     * @param experienceHour
     * @param expUserMobile
     * @param expUserName
     * @param expProductId
     * @return
     */
    @RequestMapping(value = "/add-experience", method = RequestMethod.PATCH)
    public @ResponseBody String onAddExperience(ExperienceStat experienceStat) {
        
        Result result = new Result();
        
        try {
            Principal coach = principalService.load(Principal.class, experienceStat.getCoach());
            Site site = siteService.load(experienceStat.getSite());
            
            courseRoundService.validateCoachSite(coach, site, experienceStat.getDate());
            
            experienceStat.setRoomType(courseScheduleService.getAvailableRoomType(site, experienceStat.getDate(), experienceStat.getExperienceHour(), true).getAlias());
            
            // validate student time
            courseScheduleService.validateStudentTime(experienceStat.getExpUserMobile(), experienceStat.getDate(), experienceStat.getExperienceHour());
            
            // validate coach time
            courseScheduleService.validateCoachTime(coach, experienceStat.getDate(), experienceStat.getExperienceHour());
            
            Product product = productService.load(Product.class, experienceStat.getExpProductId());
            
            // validate user experience count
            orderService.validateUserExperienceCount(product, experienceStat.getExpUserMobile());
            
            // Step 1. create experience course order
            Order order = orderService.createExperienceOrder(product, experienceStat.getExpUserMobile(), experienceStat.getExpUserName(), site, experienceStat.getUserSourceType());
            
            if(courseRoundService.addExperienceCourse(order, coach, site, experienceStat)) {
            	//发送消息
            	
            	String message = "您有新的单节体验课程，课程时间为【"+ DateFormatUtils.format(experienceStat.getDate(), "yyyy-MM-dd") + " " + experienceStat.getExperienceHour() +"】，学员为【" + experienceStat.getExpUserName() + "】，主教练为【" + coach.getName() + "】，上课地点【"+site.getName()+"】，请准时去上课。";
                
                
                tencentHandler.sendCorpMessage(message, coach.getMobile());
            	
                result.success().message("添加体验课成功");
            } else {
                result.fail().message("支付异常");
            }
        } catch (BusinessException e) {
            result.fail().message(e.getMessage());
        } catch (Exception e) {
            logger.error("onAddExperience - ", e);
            result.fail().message("添加体验课失败");
        }
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @param siteId
     * @return
     */
    @RequestMapping(value="/cancel-experience", method = RequestMethod.GET)
    public ModelAndView cancelExperience(@RequestParam("coach") Long coachId,
                                         @RequestParam("date")String date,
                                         @RequestParam("site") Long siteId) {
        
        ModelAndView modelAndView = new ModelAndView("course/schedule/schedule-cancel-experience");
        
        Date day = DateUtils.parseDate(date, "yyyy-MM-dd");
        modelAndView.addObject("day", day);
        
        Principal coach = principalService.load(Principal.class, coachId);
        
        List<CourseSchedule> courseSchedules = courseScheduleService.listExperienceSchedule(coach, day);
        modelAndView.addObject("courseSchedules", courseSchedules);
        
        modelAndView.addObject("coachId", coachId);
        modelAndView.addObject("date", date);
        modelAndView.addObject("siteId", siteId);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param courseScheduleId
     * @return
     */
    @RequestMapping(value = "/cancel-experience", method = RequestMethod.PATCH)
    public @ResponseBody String onCancelExperience(@RequestParam("courseScheduleId") Long courseScheduleId) {
        
        Result result = new Result();
        
        try {
            
            CourseSchedule courseSchedule = courseScheduleService.load(CourseSchedule.class, courseScheduleId);
            courseRoundService.cancelExperienceCourse(courseSchedule);
            
            result.success().message("取消体验课成功");
            
        } catch (Exception e) {
            logger.error("onCancelExperience - ", e);
            result.fail().message("取消体验课失败");
        }
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @return
     */
    @RequestMapping(value="/batch-schedule", method = RequestMethod.GET)
    public ModelAndView editBatchSchedule(@RequestParam("site") Long siteId) {
        ModelAndView modelAndView = new ModelAndView("course/schedule/schedule-batch-schedule");
        
        modelAndView.addObject("siteId", siteId);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @return
     */
    @RequestMapping(value = "/batch-schedule", method = RequestMethod.PATCH)
    public @ResponseBody String onEditBatchSchedule(@RequestParam(value = "coaches", required = false) String coaches,
                                                    @RequestParam(value = "trainingDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd")Date trainingDate,
                                                    @RequestParam(value = "conferenceDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd")Date conferenceDate,
                                                    @RequestParam(value = "businessDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd")Date businessDate,
                                                    @RequestParam(value = "dutyDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd")Date dutyDate,
                                                    @RequestParam(value = "trainingHour", required = false) String trainingHour,
                                                    @RequestParam(value = "conferenceHour", required = false) String conferenceHour,
                                                    @RequestParam(value = "businessHour", required = false) String businessHour,
                                                    @RequestParam(value = "dutyHour", required = false) String dutyHour) {
        Result result = new Result();
        
        try {
            
            restCalendarService.editBatchSchedule(coaches, trainingDate, conferenceDate, businessDate, dutyDate, trainingHour, conferenceHour, businessHour, dutyHour);
            
            result.success().message("批量更改课时成功！");
            
        } catch (BusinessException e) {
            
            result.fail().message(e.getMessage());
            
        } catch (Exception e) {
            
            logger.error("onEditBatchSchedule error - ", e);
            result.fail().message("批量更改课时失败！");
        }
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param siteId
     * @return
     */
    @RequestMapping(value = "/export-view", method = RequestMethod.GET)
    public ModelAndView export(@RequestParam(value = "view") String view, @RequestParam(value = "site", required = false) Long siteId) {
        ModelAndView modelAndView = new ModelAndView("course/schedule/schedule-export");
        
        modelAndView.addObject("site", siteId);
        modelAndView.addObject("view", view);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param login
     * @param view
     * @param siteId
     * @param beginDate
     * @param endDate
     * @return
     */
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public ModelAndView onExport(@Secure Login login,
                                 @RequestParam(value = "view") String view,
                                 @RequestParam(value = "site") Long siteId,
                                 @RequestParam(value = "beginDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginDate,
                                 @RequestParam(value = "endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        ModelAndView modelAndView = new ModelAndView(new ExcelTemplateView("schedule.xls", true));
        
        // get site
        Site site;
        if(login.isSiteServer()) {
            site = login.getSite();
        } else {
            site = siteService.load(siteId);
        }
        
        List<String> coachNames = scheduleReportService.listCoachNames(site);
        List<HourlySchedule> courseSchedules = scheduleReportService.listCourseSchedule(beginDate, endDate, site);
        List<HourlySchedule> restSchedules = scheduleReportService.listRestSchedule(beginDate, endDate, site);
        List<HourlySchedule> hourlySchedules = scheduleReportHandler.generateHourlySchedules(courseSchedules, restSchedules, beginDate, endDate, coachNames, site);
        
        List<WeeklySchedule> weeklySchedules = scheduleReportHandler.generateWeeklySchedules(view, hourlySchedules, beginDate, endDate, coachNames);
        
        modelAndView.addObject("weeklySchedules", weeklySchedules);
        modelAndView.addObject("site", site);
        
        return modelAndView;
    }

    /**
     * 
     * @param coachId
     * @param date
     * @return
     */
    @RequestMapping(value="/batch-business-calendar", method = RequestMethod.GET)
    public ModelAndView batchBusinessCalendar() {
        ModelAndView modelAndView = new ModelAndView("course/schedule/schedule-batch-business-calendar");
        
        return modelAndView;
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @return
     */
    @RequestMapping(value = "/batch-business-calendar", method = RequestMethod.PATCH)
    public @ResponseBody String onBatchBusinessCalendar(@RequestParam("coaches") String coaches,
                                                        @RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd")Date date,
                                                        @RequestParam("hour") String hour) {
        Result result = new Result();
        
        try {
            
            restCalendarService.batchBusinessCalendar(coaches, date, hour);
            
            result.success().message("批量更改课时成功！");
            
        } catch (BusinessException e) {
            
            result.fail().message(e.getMessage());
            
        } catch (Exception e) {
            
            logger.error("onEditBatchSchedule error - ", e);
            result.fail().message("批量更改课时失败！");
        }
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @return
     */
    @RequestMapping(value="/annual-leave", method = RequestMethod.GET)
    public ModelAndView editAnnualLeave() {
        ModelAndView modelAndView = new ModelAndView("course/schedule/schedule-annual-leave");
        
        modelAndView.addObject("today", DateFormatUtils.format(new Date(), "yyyy-MM-dd"));
        
        return modelAndView;
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @return
     */
    @RequestMapping(value = "/annual-leave", method = RequestMethod.PATCH)
    public @ResponseBody String onEditAnnualLeave(@RequestParam("coach") Long coachId,
                                                  @RequestParam("beginDate") @DateTimeFormat(pattern = "yyyy-MM-dd")Date beginDate,
                                                  @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd")Date endDate) {
        Result result = new Result();
        
        try {
            
            Principal coach = principalService.load(Principal.class, coachId);
            
            restCalendarService.editAnnualLeave(coach, beginDate, endDate);
            
            result.success().message("排年假成功！");
            
        } catch (BusinessException e) {
            
            result.fail().message(e.getMessage());
            
        } catch (Exception e) {
            
            logger.error("onEditAnnualLeave error - ", e);
            result.fail().message("排年假成功！");
        }
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param coachId
     * @param date
     * @param siteId
     * @return
     */
    @RequestMapping(value = "/coach-experience-hour", method = RequestMethod.POST)
    public @ResponseBody String coachExperienceHour(@RequestParam("coach") Long coachId,
                                                    @RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                                                    @RequestParam("site") Long siteId) {
        Result result = new Result();
        
        try {
            
            Site site = siteService.load(siteId);

            List<Map<String, String>> hours = courseScheduleService.listAvailableExperienceHour(coachId, date, site);
            
            result.success().data("hours", hours).data("amount", hours.size()).message("获取教练可体验时间成功");
        } catch (BusinessException e) {
            
            result.fail().message(e.getMessage());
            
        } catch (Exception e) {
            
            logger.error("coachExperienceHour error - ", e);
            result.fail().message("获取教练可体验时间失败");
        }
        return JsonUtils.toJsonString(result);
    }
}
